package com.study.shengsiyuan.example07;

import com.study.shengsiyuan.example07.gen_java.thrift.Person;
import com.study.shengsiyuan.example07.gen_java.thrift.PersonService;
import org.apache.thrift.protocol.TCompactProtocol;
import org.apache.thrift.protocol.TProtocol;
import org.apache.thrift.transport.TFramedTransport;
import org.apache.thrift.transport.TSocket;
import org.apache.thrift.transport.TTransport;

public class ThriftClient {
    public static void main(String[] args) {
        // 第二个参数表示超时时间
        TTransport  transport =
                new TFramedTransport(new TSocket("localhost",8899),60000);
        TProtocol protocol =new TCompactProtocol(transport);
        PersonService.Client client = new PersonService.Client(protocol);
        try{
            transport.open();
            //发送请求，获得结果
            Person p=client.getPersonByUsername("张三");
            System.out.println("server response : "+ p);

            System.out.println("==================");
            Person p2 =new Person();
            p2.setUsername("王五");
            p2.setAge(20);
            p2.setMarried(false);
            //发送请求
            client.savePerson(p2);
        }catch (Exception e){
            e.getStackTrace();
        }finally {
            transport.close();
        }

    }
}
